package top.leyi.handle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.leyi.IService.IVisitService;
import top.leyi.utils.Result;

import java.text.SimpleDateFormat;
import java.util.Calendar;

@RequestMapping("/api/visit")
@RestController
public class VisitHandle {
    @Autowired
    IVisitService visitService;
    @GetMapping("")
    public Result doGet(@RequestParam("token") String token,
                        @RequestParam(value = "date", required = false, defaultValue = "") String date) {

           if(date.equals("")) {
               date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
           }
           return new Result(200, visitService.getDateVisit(date));
    }
}
